package com.sxpi.zixun.controller.questionscomment;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxpi.zixun.bo.QuestionsCommentBo;
import com.sxpi.zixun.common.enums.ResultStatusEnum;
import com.sxpi.zixun.common.utils.fn.asserts.Vsserts;
import com.sxpi.zixun.controller.BaseController;
import com.sxpi.zixun.pojo.QuestionsComment;
import com.sxpi.zixun.service.questionscomment.IQuestionsCommentService;
import com.sxpi.zixun.vo.QuestionsCommentVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.pug.generator.anno.PugDoc;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @Author: 董伟豪
 * @Date: 2022/9/17 10:50
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="文章评论",tabname="kss_question_comment")
public class QuestionsCommentController extends BaseController {

    private final IQuestionsCommentService questionscommentService;

    /**
     * 查询文章评论列表信息
     * @return
     */
    @PostMapping("/questionscomment/list")
    @PugDoc(name="查询文章评论列表信息")
    public List<QuestionsCommentBo> findQuestionsCommentList() {
        return questionscommentService.findQuestionsCommentList();
    }

    /**
     * 查询文章评论列表信息并分页
     * @param questionscommentVo
     * @return
     */
    @PostMapping("/questionscomment/load")
    @PugDoc(name="查询文章评论列表信息并分页")
    public IPage<QuestionsCommentBo> findQuestionsComments(@RequestBody QuestionsCommentVo questionscommentVo) {
        return questionscommentService.findQuestionsCommentPage(questionscommentVo);
    }

    /**
     * 根据文章评论id查询明细信息
     * @param id
     * @return
     */
    @PostMapping("/questionscomment/get/{id}")
    @PugDoc(name="根据文章评论id查询明细信息")
    public QuestionsCommentBo getQuestionsCommentById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id, ResultStatusEnum.ID_NOT_EMPTY);
        return questionscommentService.getQuestionsCommentById(new Long(id));
    }

    /**
     * 保存和修改文章评论
     * @param questionscomment
     * @return
     */
    @PostMapping("/questionscomment/saveupdate")
    @PugDoc(name="保存和修改文章评论")
    public QuestionsCommentBo saveupdateQuestionsComment(@RequestBody QuestionsComment questionscomment) {
        return questionscommentService.saveUpdateQuestionsComment(questionscomment);
    }

    /**
     * 根据文章评论id删除文章评论
     * @param id
     * @return
     */
    @PostMapping("/questionscomment/delete/{id}")
    @PugDoc(name="根据文章评论id删除文章评论")
    public int deleteQuestionsCommentById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id, ResultStatusEnum.ID_NOT_EMPTY);
        return questionscommentService.deleteQuestionsCommentById(new Long(id));
    }

    /**
     * 根据文章评论ids批量删除文章评论
     * @param questionscommentVo
     * @return
     */
    @PostMapping("/questionscomment/delBatch")
    @PugDoc(name="根据文章评论ids批量删除文章评论")
    public boolean delQuestionsComment(@RequestBody QuestionsCommentVo questionscommentVo) {
        Vsserts.isEmptyEx(questionscommentVo.getBatchIds(), ResultStatusEnum.ID_NOT_EMPTY);
        return questionscommentService.delBatchQuestionsComment(questionscommentVo.getBatchIds());
    }
}
